﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dhsystem.Main;
using dhSystemBLL.produceBLL;
using baseSet.importExport;
using FastReport;
using dhDataAcess.dataAcess;
using dhDataAcess.dataAcess.orderDataSetTableAdapters;
using dhSystemBLL.orderData;
using dhSystemBLL.basicData;

namespace dhsystem.produceForm.Stock
{
    public partial class FrmorderProduceList : Form
    {
        orderProduceListBLL orderProduceList = new orderProduceListBLL();
       // string state;
        public FrmorderProduceList()
        {
            InitializeComponent();
        }
        //打开窗口时显示列表数据
        private void FrmorderProduceList_Load(object sender, EventArgs e)
        {
            bindingSourceorderProduceList.DataSource = orderProduceList.getorderProduceListAll();
            dGridorderProduceList.DataSource = bindingSourceorderProduceList;
            DcolumnSet.colSet(moduleInfo.orderProduceList, dGridorderProduceList);
            toolStripStatusLabel1.Text = "数据总条数:" + dGridorderProduceList.RowCount.ToString() + "条";
        }
        //新增按钮，显示新增窗口
        //private void toolAdd_Click(object sender, EventArgs e)
        //{
        //    state = "新增";
        //    FrmorderProduceListAdd orderProduceListAdd = new FrmorderProduceListAdd(bindingSourceorderProduceList, state,"");
        //    orderProduceListAdd.ShowDialog();
        //}
        //工具栏查询按钮，查询所有列表数据
        private void toolQuery_Click(object sender, EventArgs e)
        {
            FrmDataQuery query = new FrmDataQuery(moduleInfo.orderProduceList);
            DialogResult result = query.ShowDialog();
            if (result == DialogResult.Yes)
            {
                dGridorderProduceList.DataSource = query.rTable;
            }
        }
        ////工具栏的编辑按钮,修改数据
        //private void toolEdit_Click(object sender, EventArgs e)
        //{
        //    state = "编辑";
        //    FrmorderProduceListAdd orderProduceListAdd = new FrmorderProduceListAdd(bindingSourceorderProduceList, state,"");
        //    orderProduceListAdd.ShowDialog();
        //}
        //删除按钮，删除选中行数据
        private void toolDel_Click(object sender, EventArgs e)
        {
            string produceNo = dGridorderProduceList.Rows[dGridorderProduceList.CurrentRow.Index].Cells[0].Value.ToString();
            try
            {
                DialogResult result = MessageBox.Show("是否删除原材料：" + produceNo + "！", "提示信息", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {

                    bindingSourceorderProduceList.DataSource = orderProduceList.orderProduceListDel(produceNo);
                    dGridorderProduceList.DataSource = bindingSourceorderProduceList;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            bindingSourceorderProduceList.DataSource = orderProduceList.getorderProduceListAll();
        }
        //查询按钮，按条件查询数据
        private void buttonQuery_Click(object sender, EventArgs e)
        {
            
        }
        //刷新按钮
        private void buttupdate_Click(object sender, EventArgs e)
        {
            bindingSourceorderProduceList.DataSource = orderProduceList.getorderProduceListAll();
            dGridorderProduceList.DataSource = bindingSourceorderProduceList;
            DcolumnSet.colSet(moduleInfo.orderProduceList, dGridorderProduceList);
            toolStripStatusLabel1.Text = "数据总条数:" + dGridorderProduceList.RowCount.ToString() + "条";
        }
        //工具栏退出按钮，退出窗口
        private void toolExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //datagridview第一列显示行号
        private void dGridorderProduceList_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
        {
            e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index + 1);
        }

        private void toolAdd_Click(object sender, EventArgs e)
        {

        }

        private void toolEdit_Click(object sender, EventArgs e)
        {

        }

        private void toolPrint_Click(object sender, EventArgs e)
        {
            Report r = new Report();
            DataSet ds1 = new DataSet();
            DataSet ds = new DataSet();
            orderMasterBLL orderMaster=new orderMasterBLL ();
            orderProduceListBLL orderProduce=new orderProduceListBLL ();
            orderDetailBLL orderDetail = new orderDetailBLL();
            orderDataSet.orderDetailDataTable orderDetailTable = orderDetail.getorderDetailAll();
            orderDataSet.orderMasterDataTable orderMasterTable= orderMaster .getorderMasterAll ();
            stockDataSet .orderProduceListDataTable orderproduceTable=orderProduce .getorderProduceListAll ();
            DataSetPrint.orderproduceDetailDataTable orderproduceDetailTable = new DataSetPrint.orderproduceDetailDataTable();
            DataSetPrint.orderproduceMasterDataTable orderproduceMasterTable = new DataSetPrint.orderproduceMasterDataTable();
            DataSetPrint.orderproduceMasterRow orderproducemasterRow = orderproduceMasterTable.NeworderproduceMasterRow();
            DataSetPrint.orderproduceDetailRow orderproducedetailRow = orderproduceDetailTable.NeworderproduceDetailRow();
            orderproducemasterRow.title = "生产通知单";
            foreach (stockDataSet.orderProduceListRow row in orderproduceTable)
            {
                orderproducemasterRow.produceNo = row.produceNo;
                orderproducemasterRow.createUser = row.createUser;
                orderproducemasterRow.producDate = Convert.ToString(row.producDate);

                orderproducedetailRow.orderDetailNo = row.orderDetailNo;
                orderproducedetailRow.qty = Convert.ToString(row.qty);
                orderproducedetailRow.unit = row.unit;
                orderproducedetailRow.mark = row.mark;
                orderproduceMasterTable.AddorderproduceMasterRow(orderproducemasterRow);
                orderproduceDetailTable.AddorderproduceDetailRow(orderproducedetailRow);
            }
            foreach (orderDataSet.orderMasterRow row in orderMasterTable)
            {
                orderproducemasterRow.custName = row.custNum;
                orderproducemasterRow.custpoNo = row.custPoNo;
                orderproducemasterRow.orderData =Convert .ToString ( row.orderDate);
                orderproducemasterRow.receiveDate =Convert .ToString ( row.receiveDate);
                orderproducemasterRow.address = row.address;
                orderproducemasterRow.parkMark = row.parkMark;
                orderproduceMasterTable.AddorderproduceMasterRow(orderproducemasterRow);

            }
            foreach (orderDataSet.orderDetailRow row in orderDetailTable)
            {
                orderproducedetailRow.pname = row.pname;
                orderproducedetailRow.colorName = row.colorNum;
                orderproduceDetailTable.AddorderproduceDetailRow(orderproducedetailRow);
            }
            ds.Tables.Add(orderproduceDetailTable);
            ds1.Tables.Add(orderproduceMasterTable);
            r.RegisterData(ds1);
            r.RegisterData(ds);
            r.Load(@"e:\orderproduceReport.frx");
            r.Design();
        }

        private void toolSet_Click(object sender, EventArgs e)
        {
            Report r = new Report();
            DataSet s = new DataSet();
            orderProduceListBLL orderProduce = new orderProduceListBLL();
            orderMasterBLL orderMaster = new orderMasterBLL();
            orderDetailBLL orderDetail = new orderDetailBLL();
            s.Tables.Add(orderMaster.getorderMasterAll());
            s.Tables.Add(orderDetail.getorderDetailAll());
            s.Tables.Add(orderProduce.getorderProduceListAll());
            basicForm.FrmPrint print = new basicForm.FrmPrint((object)s, moduleInfo.orderProduceList);
            r.Load(@"E:\东华软件项目\报表\orderproduce.frx");
            r.RegisterData(s );
            r.Design();
            
            //print.ShowDialog();
        }

        private void toolExport_Click(object sender, EventArgs e)
        {
            FrmExcelExport frm = new FrmExcelExport(moduleInfo.productList , dGridorderProduceList , "生产通知单信息");
            frm.ShowDialog();
        }
    }
}
